package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.SupplierService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.SupplierBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.SupplierVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.javassist.expr.NewArray;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/supplier")
@Api(tags = "供应商")
public class SupplierController extends BaseController {

    @Resource
    private SupplierService supplierService;

    @PostMapping("/querySupplierCategory")
    @Auth(product = BaseEnum.ProductEnum.API)
    @ApiOperation("供应商列表Api")
    public RestVo<PageVo<SupplierVo>> querySupplierCategory(@RequestBody SupplierBo bo) {
        PageBo<SupplierBo> pageBo= new PageBo<>();
        pageBo.setParam(bo);
        return RestVo.ok(supplierService.getList(pageBo));
    }

    @PostMapping("/create")
    @ApiOperation("创建供应商")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<String> create(@Valid @RequestBody SupplierBo bo) {
        return RestVo.ok(supplierService.create(bo));
    }

    @PostMapping("/list")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("供应商列表")
    public RestVo<PageVo<SupplierVo>> querySupplier(@RequestBody PageBo<SupplierBo> bo) {
        return RestVo.ok(supplierService.getList(bo));
    }
}
